﻿using System;
using System.Data;
using System.Collections;
using CE.Database;

/// <summary>
/// Summary description for CarMoreDetailsDB
/// </summary>
/// 
namespace CE.CarInsurance
{
    public class CarMoreDetailsDB
    {
        public Int64 Insert(CarMoreDetails carmoredetails)
        {
            MyDatabase _db = new MyDatabase("GG_CRMDBConnectionString");
            Int64 _result = -1;
            string _spName = "sprocCarMoreDetailInsertUpdateSingleItem";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CarId", carmoredetails.CarId);
            _sPara.Add("@ProviderCompanyId", carmoredetails.ProviderCompanyId);
            _sPara.Add("@Name", carmoredetails.Name);
            _sPara.Add("@Title", carmoredetails.Title);
            _sPara.Add("@Dispalcement", carmoredetails.Dispalcement);
            _sPara.Add("@VehicleWeight", carmoredetails.VehicleWeight);
            _sPara.Add("@NumberofSeat", carmoredetails.NumberofSeat);
            //_sPara.Add("@Beneficiary", carmoredetails.Beneficiary);
            _sPara.Add("@EngineNumber", carmoredetails.EngineNumber);
            _sPara.Add("@ChassisNumber", carmoredetails.ChassisNumber);
            _sPara.Add("@QuoteRefNo", carmoredetails.QuoteRefNo);
            _sPara.Add("@RefCEUserId", carmoredetails.RefCEUserId);
            _sPara.Add("@AgentId", carmoredetails.AgentId);
            _sPara.Add("@Status", carmoredetails.Status);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public CarMoreDetails GetCarMoreDetails(Int64 CarId, Int64 RefCEUserId, Int64 ProviderCompanyId)
        {
            CarMoreDetails _carmoredetails = null;
            MyDatabase _db = new MyDatabase("GG_CRMDBConnectionString");
            string _spName = "sprocCarMoreDetailSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CarId", CarId);
            _spara.Add("@RefCEUserId", RefCEUserId);
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);
            if (_dt != null)
            {
                if (_dt.Rows.Count > 0)
                {
                    _carmoredetails = new CarMoreDetails();
                    _carmoredetails = FillDataRecord(_dt);
                }
            }
            return _carmoredetails;
        }

        private CarMoreDetails FillDataRecord(DataTable myDataTable)
        {
            CarMoreDetails myCarMoreDetail = new CarMoreDetails();
            myCarMoreDetail.CarMoreDetailId = Convert.ToInt64(myDataTable.Rows[0]["CarMoreDetailId"].ToString());
            myCarMoreDetail.CarId = Convert.ToInt64(myDataTable.Rows[0]["CarId"].ToString());
            myCarMoreDetail.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[0]["ProviderCompanyId"].ToString());
            myCarMoreDetail.Title = myDataTable.Rows[0]["Title"].ToString();
            myCarMoreDetail.Name = myDataTable.Rows[0]["Name"].ToString();
            myCarMoreDetail.Dispalcement = myDataTable.Rows[0]["Dispalcement"].ToString();
            myCarMoreDetail.VehicleWeight = myDataTable.Rows[0]["VehicleWeight"].ToString();
            myCarMoreDetail.NumberofSeat = Convert.ToInt16(myDataTable.Rows[0]["OfficePhoneNo"].ToString());
            //myCarMoreDetail.Beneficiary = myDataTable.Rows[0]["Beneficiary"].ToString();
            myCarMoreDetail.QuoteRefNo = myDataTable.Rows[0]["QuoteRefNo"].ToString();
            myCarMoreDetail.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            myCarMoreDetail.AgentId = Convert.ToInt64(myDataTable.Rows[0]["AgentltId"].ToString());
            myCarMoreDetail.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());


            return myCarMoreDetail;
        }

        public DataSet GetCarMoreDetailsDS(Int64 CarId, Int64 RefCEUserId, Int64 ProviderCompanyId)
        {
            DataSet _result = null;
            MyDatabase _db = new MyDatabase("GG_CRMDBConnectionString");
            string _spName = "sprocCarMoreDetailSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CarId", CarId);
            _spara.Add("@RefCEUserId", RefCEUserId);
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);


            using (DataSet _ds = _db.GetDataSet(_spName, _spara))
            {
                if (_ds != null && _ds.Tables.Count > 0 && _ds.Tables[0].Rows.Count > 0)
                {
                    _result = _ds;
                }
            }
            return _result;
        }

    }
}